"""
:create time: 2020/1/18 16:04 
:author: may
:desc: 获取文件路径，默认根目录为 C:/Users/May/Downloads
"""
import os
import config


def get_filepath(name):
    """根据文件名从文件夹中获取文件"""

    path = config.get_cfg('server', 'export_path')
    files = os.listdir(path)
    excels = []
    for file in files:
        if name in file and file.endswith('.xls'):
            filepath = path + '/' + file
            excels.append(filepath)
    if excels:
        excels.sort(reverse=True)
        return excels[0]
    else:
        return None

def clear_old_excel(name):
    path = config.get_cfg('server', 'export_path')
    files = os.listdir(path)
    for file in files:
        if name in file and file.endswith('.xls'):
            filepath = path + '/' + file
            os.remove(filepath)